﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="main.aspx.cs" Inherits="analyze_main" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>KYOWON CREATIVE 지문분석 System beta</title>
<link href="/css/layout.css" type="text/css" rel="stylesheet"/>
<script>
    function form_submit()
    {
        var input_form = document.input_form;
        
        if (input_form.text.value == "")
        {
            alert("분석 대상 지문을 입력해주세요.");
            input_form.text.focus();
            return;
        }
        
        input_form.uploadfile.value = "";
        input_form.submit();
    }
    
    function upload()
    {
        var input_form = document.input_form;
        
        if (input_form.uploadfile.value == "")
        {
            alert("분석 대상 지문 파일을 선택해주세요.");
            input_form.uploadfile.focus();
            return;
        }
        
        input_form.text.value = "";
        input_form.submit();
    }
    
    function text_clear()
    {
        var input_form = document.input_form;
        input_form.text.value = ""; 
        input_form.text.focus();   
    }
    
    function excel_download()
    {
        var excel_form = document.excel_form;
        
        excel_form.word_excel.value = document.getElementById("word_excel").innerHTML;
        excel_form.submit();
    }    
</script>
</head>
<body>
<form id=excel_form name=excel_form method=post action="excel.aspx">
    <input type=hidden name="word_excel" />
</form>
<form id=input_form name=input_form method="post" action="main.aspx" onsubmit="return false" enctype="multipart/form-data">
<div class="full_wrap">
	<h1 class="center">KYOWON CREATIVE 지문분석 System <sup>beta</sup></h1>
    <h2>분석 대상 지문&nbsp;&nbsp;&nbsp;<input type=file name="uploadfile" class="in_style" />&nbsp;<input type="button" class="btn_analysis" value="업로드" onclick="upload()" style="height:20px" /> (txt, docx 파일만 지원)</h2>
    <textarea name="text" style="height:300px"><%= _text %></textarea>
    <div class="center" style="margin-top:15px;">
        <input type="button" class="btn_analysis" value="분석하기" onclick="form_submit()" />&nbsp;<input type="button" class="btn_analysis" value="지문삭제" onclick="text_clear()" /></div>
<%
    if (_text != "")
    {
%>    
    <h2>분석 결과</h2><input type="button" class="btn_analysis" style="height:23px;width:180px;" value="분석결과 Excel Download" onclick="excel_download()" /><br /><br />
    <div id="word_excel">
    <h3 class="type1">1.1) 레벨별 단어수 - 중복제외</h3>
    <table class="basic">
    <colgroup>
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    </colgroup>
    <thead>
    <tr>
    	<th>K2 이하</th>
    	<th>K3</th>
    	<th>K4</th>
    	<th>K5</th>
    	<th>K6</th>
    	<th>K7</th>
    	<th>K8</th>
    	<th>K9</th>
    	<th>기타단어</th>
    	<th>합계</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    	<td class="tdc"><%= GetWordLevelCount(0) %></td>
    	<td class="tdc"><%= GetWordLevelCount(1) %></td>
    	<td class="tdc"><%= GetWordLevelCount(2) %></td>
    	<td class="tdc"><%= GetWordLevelCount(3) %></td>
    	<td class="tdc"><%= GetWordLevelCount(4) %></td>
    	<td class="tdc"><%= GetWordLevelCount(5) %></td>
    	<td class="tdc"><%= GetWordLevelCount(6) %></td>
    	<td class="tdc"><%= GetWordLevelCount(7) %></td>
    	<td class="tdc"><%= GetWordLevelCount(-1) %></td>
    	<td class="tdc"><%= GetWordLevelCount(-2) %></td>
    </tr>
    <tr>
    	<td class="tdc"><%= GetWordLevelPercent(0) %>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(1)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(2)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(3)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(4)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(5)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(6)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(7)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(-1)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercent(-2)%>%</td>
    </tr>
    </tbody>
    </table>
    <br />
    <h3 class="type1">1.2) 레벨별 단어수 - 중복포함</h3>
    <table class="basic">
    <colgroup>
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    <col width="10%" />
    </colgroup>
    <thead>
    <tr>
    	<th>K2 이하</th>
    	<th>K3</th>
    	<th>K4</th>
    	<th>K5</th>
    	<th>K6</th>
    	<th>K7</th>
    	<th>K8</th>
    	<th>K9</th>
    	<th>기타단어</th>
    	<th>합계</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(0) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(1) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(2) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(3) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(4) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(5) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(6) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(7) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(-1) %></td>
    	<td class="tdc"><%= GetWordLevelCountDuplicate(-2) %></td>
    </tr>
    <tr>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(0) %>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(1)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(2)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(3)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(4)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(5)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(6)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(7)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(-1)%>%</td>
    	<td class="tdc"><%= GetWordLevelPercentDuplicate(-2)%>%</td>
    </tr>
    </tbody>
    </table>    
    <br />
    <h3>2) 난이도 판별 양적요인</h3>
    <div>
        <table class="basic">
        <colgroup>
        <col width="50%" />
        <col width="50%" />
        </colgroup>
        <tbody>
        <tr>
    	    <th class="tdc">문장의 평균 단어수</th>
    	    <td class="tdc"><%= GetSentenceWordCount() %></td>
        </tr>
        <tr>
    	    <th class="tdc">단어중복사용비율</th>
    	    <td class="tdc"><%= GetRepetitionPercent() %>%</td>
        </tr>
        </tbody>
        </table>    
    </div>
    <br />
    <h3 class="type1">3.1) Sight words group - 중복제외</h3>
    <div>
    <table class="basic">
    <colgroup>
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="15%" />
    </colgroup>
    <thead>
    <tr>
    	<th colspan="2">S1</th>
    	<th colspan="2">S2</th>
    	<th rowspan="2">기타단어</th>
        <th rowspan="2">합계</th>
    </tr>
    <tr>
    	<th>명사</th>
        <th>기타품사</th>
        <th>명사</th>
        <th>기타품사</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    	<td class="tdc"><%= GetSightLevelCount(1,1) %></td>
    	<td class="tdc"><%= GetSightLevelCount(1,2)%></td>
    	<td class="tdc"><%= GetSightLevelCount(2,1) %></td>
    	<td class="tdc"><%= GetSightLevelCount(2,2) %></td>
    	<td class="tdc"><%= GetSightLevelCount(-1,-1)%></td>
    	<td class="tdc"><%= GetSightLevelCount(-2,-2)%></td>
    </tr>
    <tr>
    	<td class="tdc"><%= GetSightLevelPercent(1,1) %>%</td>
    	<td class="tdc"><%= GetSightLevelPercent(1,2) %>%</td>
    	<td class="tdc"><%= GetSightLevelPercent(2,1) %>%</td>
    	<td class="tdc"><%= GetSightLevelPercent(2,2) %>%</td>
    	<td class="tdc"><%= GetSightLevelPercent(-1,-1)%>%</td>
    	<td class="tdc"><%= GetSightLevelPercent(-2,-2)%>%</td>
    </tr>
    </tbody>
    </table>
    </div>
    <br />
    <h3 class="type1">3.2) Sight words group - 중복포함</h3>
    <div>
    <table class="basic">
    <colgroup>
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="15%" />
    </colgroup>
    <thead>
    <tr>
    	<th colspan="2">S1</th>
    	<th colspan="2">S2</th>
    	<th rowspan="2">기타단어</th>
        <th rowspan="2">합계</th>
    </tr>
    <tr>
    	<th>명사</th>
        <th>기타품사</th>
        <th>명사</th>
        <th>기타품사</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    	<td class="tdc"><%= GetSightLevelCountDuplicate(1,1) %></td>
    	<td class="tdc"><%= GetSightLevelCountDuplicate(1, 2)%></td>
    	<td class="tdc"><%= GetSightLevelCountDuplicate(2, 1)%></td>
    	<td class="tdc"><%= GetSightLevelCountDuplicate(2, 2)%></td>
    	<td class="tdc"><%= GetSightLevelCountDuplicate(-1, -1)%></td>
    	<td class="tdc"><%= GetSightLevelCountDuplicate(-2, -2)%></td>
    </tr>
    <tr>
    	<td class="tdc"><%= GetSightLevelPercentDuplicate(1,1) %>%</td>
    	<td class="tdc"><%= GetSightLevelPercentDuplicate(1, 2)%>%</td>
    	<td class="tdc"><%= GetSightLevelPercentDuplicate(2, 1)%>%</td>
    	<td class="tdc"><%= GetSightLevelPercentDuplicate(2, 2)%>%</td>
    	<td class="tdc"><%= GetSightLevelPercentDuplicate(-1, -1)%>%</td>
    	<td class="tdc"><%= GetSightLevelPercentDuplicate(-2, -2)%>%</td>
    </tr>
    </tbody>
    </table>
    </div>
    <br />
    <h3>4) Sight words 단어 상세</h3> 
    <div>
    <table class="basic">
    <colgroup>
    <col width="15%" />
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="17%" />
    <col width="" />
    </colgroup>
    <thead>
        <th>S Level</th>
        <th>Head Word</th>
        <th>Frequency</th>
        <th>품사</th>
        <th>Dolch Level</th>
        <th>KWC Level</th>
    </thead>
    <tbody>
<%
    for (int i = 0; i < 5; i++)
    {
        int sightlevel, category;
        switch (i)
        {
            case 0: sightlevel = 1; category = 1; break;
            case 1: sightlevel = 1; category = 2; break;
            case 2: sightlevel = 2; category = 1; break;
            case 3: sightlevel = 2; category = 2; break;
            default: sightlevel = -1; category = -1; break;
        }
        string title_level = (sightlevel>0) ? "S" + Convert.ToString(sightlevel) : "기타단어";
        
       
        for (int j = 0; j < _sortsightwordlist[i].Count; j++)
        {
            SightWordInfo info = (SightWordInfo)_sortsightlist[i][j];
            
            string title_category;
            if (category == 1)
                title_category = "명사";
            else if (category == 2)
                title_category = "기타품사";
            else
                title_category = "-";

            string title_dolchlevel;
            if (info.dolchlevel == 1)
                title_dolchlevel = "Pre-primer";
            else if (info.dolchlevel == 2)
                title_dolchlevel = "Primer";
            else if (info.dolchlevel == 3)
                title_dolchlevel = "1st Grade";
            else if (info.dolchlevel == 4)
                title_dolchlevel = "2nd Grade";
            else if (info.dolchlevel == 5)
                title_dolchlevel = "3rd Grade";
            else
                title_dolchlevel = "-";

            string title_kwclevel = (info.kwclevel >= 0) ? "K" + Convert.ToString(info.kwclevel + 2) : "기타단어";
            if (info.kwclevel == 0)
                title_kwclevel += " 이하";
            
%>
    <tr>
    	<th valign="baseline" ><%= title_level %></th>
        <td><%= _sortsightwordlist[i][j] %></td>
        <td><%= info.wordcount %></td>
        <td><%= title_category %></td>
        <td><%= title_dolchlevel%></td>
        <td><%= title_kwclevel%></td>
    </tr>
<%               
        }
    }
%>    

    </tbody>
    </table>
    </div>
    <br />
    <h3>5.1) 레벨별 단어</h3> 
    <div id="word_excel1">
    <table class="basic">
    <colgroup>
    <col width="12.5%" />
    <col width="" />
    <col width="" />
    </colgroup>
    <thead>
        <th>Level</th>
        <th>Head Word</th>
        <th>Frequency</th>
    </thead>
    <tbody>
<%
    for (int i = 0; i < 9; i++)
    {
        int wordlevel = (i < 8) ? i : -1;
        string title = (i < 8) ? "K" + Convert.ToString(i+2) : "기타단어";
        if (i == 0)
            title += " 이하";
        
        for (int j = 0; j < _sortwordlist[i].Count; j++)
        {
            WordInfo info = (WordInfo)_sortlist[i][j];
%>
    <tr>
    	<th valign="baseline" ><%= title %></th>
        <td><%= _sortwordlist[i][j] %></td>
        <td><%= info.wordcount %></td>
    </tr>
<%               
        }
    }
%>    
    </tbody>
    </table>
    </div>
    <h3>5.2) 레벨별 단어 상세</h3>
    <div id="word_excel2">
    <table class="basic">
    <colgroup>
    <col width="12.5%" />
    <col width="" />
    <col width="" />
    <col width="" />
    <col width="" />
    </colgroup>
    <thead>
        <th>Level</th>
        <th>Head Word</th>
        <th>Frequency</th>
        <th>Variation</th>
        <th>Frequency</th>
    </thead>
    <tbody>
<%
    for (int i = 0; i < 9; i++)
    {
        int wordlevel = (i < 8) ? i : -1;
        string title = (i < 8) ? "K" + Convert.ToString(i + 2) : "기타단어";
        if (i == 0)
            title += " 이하";
        
        for (int j = 0; j < _sortwordlist[i].Count; j++)
        {
            WordInfo info = (WordInfo)_sortlist[i][j];
            WordInfo subinfo;

            ArrayList subsortlist = new ArrayList();
            ArrayList subwordlist = new ArrayList();
            
            IDictionaryEnumerator suben = info.subwordlist.GetEnumerator();

            while (suben.MoveNext())
            {
                subinfo = (WordInfo)suben.Value;

                subsortlist.Add(subinfo);
                subwordlist.Add(suben.Key.ToString());
            }

            for (int k = 0; k < subsortlist.Count - 1; k++)
            {
                for (int l = k + 1; l < subsortlist.Count; l++)
                {
                    WordInfo info1 = (WordInfo)subsortlist[k];
                    WordInfo info2 = (WordInfo)subsortlist[l];
                    string word1 = (string)subwordlist[k];
                    string word2 = (string)subwordlist[l];

                    if (info1.wordcount < info2.wordcount)
                    {
                        subsortlist[l] = info1;
                        subsortlist[k] = info2;

                        subwordlist[l] = word1;
                        subwordlist[k] = word2;
                    }
                }
            }

            subinfo = (WordInfo)subsortlist[0];
%>
    <tr>
    	<th valign="baseline" ><%= title %></th>
        <td><%= _sortwordlist[i][j]%></td>
        <td><%= info.wordcount %></td>
        <td><%= subwordlist[0] %></td>
        <td><%= subinfo.wordcount %></td>
    </tr>
<%             
            for (int k=1; k<subsortlist.Count; k++)
            {
                subinfo = (WordInfo)subsortlist[k];
%>
    <tr>
    	<th valign="baseline" ></th>
        <td></td>
        <td></td>
        <td><%= subwordlist[k] %></td>
        <td><%= subinfo.wordcount %></td>
    </tr>
<%                         
            }
        }
    }
%>    
    </tbody>
    </table>  
    </div>  
    </div>
<%
    }
%>    
</div><!--full_wrap-->
</form>
</body>
</html>
